// pages/historicFlow/historicFlow.js
//已办流程
var app = getApp()
var utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    histoicFlowList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (obj) {
    var that = this,
      procInsId = obj.procInsId,
      processDefinitionId = obj.processDefinitionId,
      executionId = obj.executionId
    if (utils.checkNetWorkStatus() == false) {
      console.log('网络错误');
      wx.navigateBack({
        delta:1
      })
      wx.showToast({
        title: '网络错误请检查',
        image: '../../images/fail.png',
        duration: 2000,
      })
    } else {
      var url = app.GLOBAL_CONFIG.commonUrl + app.GLOBAL_CONFIG.historicFlowView + "?procInsId=" + procInsId + "&processDefinitionId=" + processDefinitionId + "&executionId=" + executionId,
       cookie = app.globalData.cookie 
       utils.getRequest(url, cookie,app, that, that.successOper, function (res) {
         wx.navigateBack({
           delta:1
         })
         wx.showToast({
           title: '获取数据失败，请稍后重试',
           image: '../../images/fail.png',
           duration: 2000
         })
       })
    }  
  },

  successOper:function(res,that){
    var list = [], histoicFlowList = res.data.histoicFlowList
    for (var i = 0; i < histoicFlowList.length; i++) {
      var activityId = histoicFlowList[i].histIns.activityId
      if (activityId == 'contractCountersignOpinion' || activityId == 'contractAmendOpinion') {//会签
        var str = JSON.parse(histoicFlowList[i].comment)
        histoicFlowList[i].comment = str
        list.push(histoicFlowList[i])
      } else {
        list.push(histoicFlowList[i])
      }
    }
    that.setData({
      histoicFlowList: list
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  }

})